package com.songtai.service.impl;

import java.util.List;

import com.songtai.dao.ImageDao;
import com.songtai.po.PhotoObj;
import com.songtai.service.ImageService;
import com.songtai.util.CommenUtil;
import com.songtai.util.Pager;

/**
 * @author 赵中杨
 * @email zhaozhongyang717@gmail.com
 * @date 2010 2010-4-20 下午03:58:20
 */
public class ImageServiceImpl implements ImageService {
	private ImageDao imageDao;

	@Override
	public void addImage(PhotoObj product) {
		imageDao.addImage(product);
	}

	@Override
	public int deleteImage(String pid) {
		return imageDao.deleteImage(pid);
	}

	@Override
	public Pager<PhotoObj> getImage(Long nodeid, int currentPage, int pageSize) {
		return imageDao.getImage(nodeid, currentPage, pageSize);
	}

	@Override
	public List<PhotoObj> getRecentImage(int pageSize, String type,Long nodeid) {
		return imageDao.getRecentImage(pageSize, type,nodeid);
	}

	/**
	 * 获取产品和案例
	 * 
	 * @param currentPage
	 * @param pageSize
	 * @param type
	 * @param nideid
	 * @return
	 */
	public Pager<PhotoObj> getAllImage(int currentPage, int pageSize, String type, Long nodeid) {
		if (nodeid < 1) {
			return imageDao.getAllImage(currentPage, pageSize, type);
		} else {
			return imageDao.getAllImage(currentPage, pageSize, type, nodeid);
		}
	}

	public Pager<PhotoObj> getAllImagesGroupByBiaoqian(int currentPage, int pageSize, String type, Long nodeid) {
		if (nodeid < 1) {
			return imageDao.getAllImage(currentPage, pageSize, type);
		} else {
			return imageDao.getAllImageGroupByBiaoqian(currentPage, pageSize, type, nodeid);
		}
	}

	/**
	 * 搜索案例和产品
	 */
	@Override
	public Pager<PhotoObj> getAllImage(String keyword, int currentPage, int pageSize, String type) {
		return imageDao.searchImage(currentPage, pageSize, type, keyword);
	}

	@Override
	public PhotoObj getImageById(String pid) {
		return imageDao.getImageById(pid);
	}

	/**
	 * @return the imageDao
	 */
	public ImageDao getImageDao() {
		return imageDao;
	}

	/**
	 * @param imageDao
	 *            the imageDao to set
	 */
	public void setImageDao(ImageDao imageDao) {
		this.imageDao = imageDao;
	}

	@Override
	public boolean updateImage(PhotoObj obj) {
		if (obj != null && !CommenUtil.isEmpty(obj.getId())) {
			PhotoObj obj1 = imageDao.getImageById(obj.getId());
			if (obj1 != null) {
				obj1.setElseContent(obj.getElseContent());
				obj1.setTitle(obj.getTitle());
				obj1.setReMark(obj.getReMark());
				obj1.setName(obj.getName());
				imageDao.updateImage(obj1);
				return true;
			}
		}
		return false;
	}

	@Override
	public List<PhotoObj> getImageByNodeid(Long nodeid, int pageSize, String type) {
		return imageDao.getImageByNodeid(nodeid, pageSize, type);
	}

	@Override
	public List<PhotoObj> getGroupImages(String pid) {
		PhotoObj obj = imageDao.getImageById(pid);
		if (obj != null && !CommenUtil.isEmpty(obj.getId())) {
			return imageDao.getImagesByBiaoqian(PhotoObj.TYPE_CASE, obj.getReMark(), obj.getNid());
		}
		return null;
	}

}
